package com.gu.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.boot.exception.DiyException;
import com.gu.entity.AclRolePermission;
import com.gu.service.AclRolePermissionService;
import com.gu.mapper.AclRolePermissionMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 *
 */
@Service
public class AclRolePermissionServiceImpl extends ServiceImpl<AclRolePermissionMapper, AclRolePermission>
        implements AclRolePermissionService {

    //给角色分配菜单；
    @Override
    public void saveRolePermissionRelationShip(String roleId, String[] permissionIds) {
       if(StringUtils.isEmpty(roleId)||permissionIds==null){
           throw new DiyException("444","角色Id或者权限Id不能为空");
       }
        List<AclRolePermission> rolePermissionList = new ArrayList<>();
        for (String permissionId : permissionIds) {
            if (StringUtils.isEmpty(permissionId)) continue;
            AclRolePermission rolePermission = new AclRolePermission();
            rolePermission.setRoleId(roleId);
            rolePermission.setPermissionId(permissionId);
            rolePermissionList.add(rolePermission);
        }
        this.saveBatch(rolePermissionList);
    }
}




